package udpPrac;

import java.io.IOException;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Receive {

    public static void main(String[] args) throws IOException {

        DatagramSocket ds = new DatagramSocket(10086);

        byte[] bytes=new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

        while (true) {
            ds.receive(dp);//接收数据包


            //解析接收过来的数据包
            byte[] data = dp.getData();
            InetAddress address = dp.getAddress();
            int port = dp.getPort();
            int length = dp.getLength();
            System.out.println("接收到的数据"+new String(data,0,length));
            System.out.println("该数据是从"+address+"这台电脑中的"+port+"这个端口发出的");
        }



    }
}
